<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php


class CDiscuzUcUser implements IUserSourceInterface
{
    private $_initialized = false;
    Private $_dbLink;
    
    public function  __construct()
    {
        $con = CDbConn::getInstance();
        $dbSource = $con->getUserSource();
        if ("discuz" != $dbSource){
            $con->reConnect();
        }
        $this->_dbLink = $con->getCon();
    }


    
    public function getUser($userInfo){
        if (!$this->_dbLink){
            return false;
        }

        $userName = $userInfo['userName'];
        $password = $userInfo['password'];

        $db = CDbConn::getInstance();
        $userTableName = $db->getUserTableName();
                $sql = "select * from $userTableName where username='{$userName}'";
        $db_data =  $db->selectDb($sql);

        if (empty($db_data) || count($db_data) == 0){
            return false;
        }

        $passwordSig = $this->_passSig($password, $db_data[0]['salt']);
        if ($db_data[0]['password'] != $passwordSig){
            return false;
        }

        $retData = array();
        $retData['user_name'] = $userName;
        $retData['nick']      = $userName;
        $retData['email']     = $db_data[0]['email'];
        return $retData;
    }

    
    private function _passSig($password, $salt){
        $md5password =  md5(md5($password).$salt);
        return $md5password;
    }


    
    public function judgeSelf(){
        return false;
    }
     
}
?>